package com.ruoyi.buss.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.buss.utils.Params;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.buss.system.domain.SysBusparams;
import com.ruoyi.buss.system.service.ISysBusparamsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 系统参数配置Controller
 * 
 * @author zjh
 * @date 2021-07-27
 */
@RestController
@RequestMapping("/Sys_Busparams")
public class SysBusparamsController extends BaseController
{
    @Autowired
    private ISysBusparamsService sysBusparamsService;

    /**
     * 查询系统参数配置列表
     */
    @PreAuthorize(hasPermi = "buss:Sys_Busparams:list")
    @GetMapping("/list")
    public TableDataInfo list(SysBusparams sysBusparams)
    {
        startPage();
        List<SysBusparams> list = sysBusparamsService.selectSysBusparamsList(sysBusparams);
        return getDataTable(list);
    }

    /**
     * 导出系统参数配置列表
     */
    @PreAuthorize(hasPermi = "buss:Sys_Busparams:export")
    @Log(title = "系统参数配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBusparams sysBusparams) throws IOException
    {
        List<SysBusparams> list = sysBusparamsService.selectSysBusparamsList(sysBusparams);
        ExcelUtil<SysBusparams> util = new ExcelUtil<SysBusparams>(SysBusparams.class);
        util.exportExcel(response, list, "系统参数配置数据");
    }

    /**
     * 获取系统参数配置详细信息
     */
    @PreAuthorize(hasPermi = "buss:Sys_Busparams:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(sysBusparamsService.selectSysBusparamsById(id));
    }

    /**
     * 新增系统参数配置
     */
    @PreAuthorize(hasPermi = "buss:Sys_Busparams:add")
    @Log(title = "系统参数配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBusparams sysBusparams)
    {
        return toAjax(sysBusparamsService.insertSysBusparams(sysBusparams));
    }

    /**
     * 修改系统参数配置
     */
    @PreAuthorize(hasPermi = "buss:Sys_Busparams:edit")
    @Log(title = "系统参数配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBusparams sysBusparams)
    {
        return toAjax(sysBusparamsService.updateSysBusparams(sysBusparams));
    }

    /**
     * 删除系统参数配置
     */
    @PreAuthorize(hasPermi = "buss:Sys_Busparams:remove")
    @Log(title = "系统参数配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysBusparamsService.deleteSysBusparamsByIds(ids));
    }

    /**
     * 获取系统参数配置详细信息
     */
    @GetMapping("/ifAdmin")
    public AjaxResult ifAdmin(@RequestParam("code")  String code,@RequestParam("value")  String value)
    {
        try {
            int flag = sysBusparamsService.ifAdmin(code,value);
            if(flag>0){
                return AjaxResult.success(true);
            }  else {
                return AjaxResult.success(false);
            }
        } catch (Exception e){
            return AjaxResult.success(false);
        }
    }
}
